FROM centos:8

ENV PHP_VERSION=7.4
ENV SWOOLE_VERSION=4.5.9

MAINTAINER sreeb228@163.com

#安装依赖包
RUN yum install -y curl wget openssl-devel gcc-c++ make autoconf zip unzip

#配置dnf
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo \
    && yum makecache

#安装php和依赖扩展
RUN dnf module reset php \
    && dnf module -y install php:${PHP_VERSION} \
    && dnf install -y php-devel php-openssl php-json php-mysqlnd php-sockets php-mbstring

#安装swoole
#源码编译安装出现了Cannot find config.m4.报错，暂未解决。
#RUN wget https://pecl.php.net/get/swoole-${SWOOLE_VERSION}.tgz -O swoole.tar \
#    && mkdir -p swoole \
#    && tar -xvf swoole.tar -C swoole \
#    && rm swoole.tar \
#    && ( \
#    cd swoole \
#    && phpize \
#    && ./configure --enable-openssl --enable-http2 --enable-swoole-json \
#    && make \
#    && make install \
#    ) \
#    && echo "extension=swoole" > /etc/php.d/30-swoole.ini \
#    && rm -r swoole

#安装pecl
RUN wget http://pear.php.net/go-pear.phar \
    && php go-pear.phar
#使用pecl安装swoole
RUN pecl install swoole \
    && echo "extension=swoole" > /etc/php.d/30-swoole.ini \
    && echo "swoole.use_shortname=off" >> /etc/php.d/30-swoole.ini

#安装composer
RUN curl -sS https://getcomposer.org/installer | php \
    && mv composer.phar /usr/bin/composer \
    && composer config -g repo.packagist composer https://mirrors.cloud.tencent.com/composer/

#安装redis和php-redis
RUN dnf install -y redis \
    && pecl install redis \
    && echo "extension=redis" > /etc/php.d/30-redis.ini
#安装mysql
RUN dnf install -y mysql-server

#执行系统进程（不然无法使用systemctl等系统命令）
ENTRYPOINT ["/usr/sbin/init"]